package com.hyphenate.easeui.utils;

import android.content.Context;
import android.content.SharedPreferences;

/**
 * Created by kelvin on 2016/9/18.
 */
public class SpUtil {
    private static final String SP_NAME = "APP_CONFIG";
    private static SharedPreferences sp;


    private static SharedPreferences getSp(Context context) {
        sp = context.getSharedPreferences(SP_NAME, Context.MODE_PRIVATE);
        return sp;
    }

    private static SharedPreferences.Editor getEditor(Context context) {
        SharedPreferences.Editor editor = getSp(context).edit();
        return editor;
    }


    public static String getLongtitude(Context context) {
        return getSp(context).getString("longtitude", "");
    }

    public static void putLongtitude(Context context, String longtitude) {
        SharedPreferences.Editor editor = getSp(context).edit();
        editor.putString("longtitude", longtitude);
        editor.commit();
    }

    public static String getLatitude(Context context) {
        return getSp(context).getString("latitude", "");
    }

    public static void putLatitude(Context context, String latitude) {
        SharedPreferences.Editor editor = getSp(context).edit();
        editor.putString("latitude", latitude);
        editor.commit();
    }


    /**
     * 设置新消息是否通知
     *
     * @param context
     * @param isSettingMsgNotification
     */
    public static void setSettingMsgNotification(Context context, boolean isSettingMsgNotification) {
        SharedPreferences.Editor editor = getSp(context).edit();
        editor.putBoolean("isSettingMsgNotification", isSettingMsgNotification);
        editor.commit();
    }

    public static boolean getSettingMsgNotification(Context context) {
        SharedPreferences sp = getSp(context);
        boolean isSettingMsgNotification = sp.getBoolean("isSettingMsgNotification", true);
        return isSettingMsgNotification;
    }

    /**
     * 设置新消息是否有声音
     *
     * @param context
     * @param isSettingMsgSound
     */
    public static void setSettingMsgSound(Context context, boolean isSettingMsgSound) {
        SharedPreferences.Editor editor = getSp(context).edit();
        editor.putBoolean("isSettingMsgSound", isSettingMsgSound);
        editor.commit();
    }

    public static boolean getSettingMsgSound(Context context) {
        SharedPreferences sp = getSp(context);
        boolean isSettingMsgSound = sp.getBoolean("isSettingMsgSound", true);
        return isSettingMsgSound;
    }

    /**
     * 设置新消息是否有震动
     *
     * @param context
     * @param isSettingMsgVibrate
     */
    public static void setSettingMsgVibrate(Context context, boolean isSettingMsgVibrate) {
        SharedPreferences.Editor editor = getSp(context).edit();
        editor.putBoolean("isSettingMsgVibrate", isSettingMsgVibrate);
        editor.commit();
    }

    public static boolean getSettingMsgVibrate(Context context) {
        SharedPreferences sp = getSp(context);
        boolean isSettingMsgVibrate = sp.getBoolean("isSettingMsgVibrate", false);
        return isSettingMsgVibrate;
    }

    /**
     * 设置设置使用扬声器播放语音
     *
     * @param context
     * @param isSettingMsgSpeaker
     */
    public static void setSettingMsgSpeaker(Context context, boolean isSettingMsgSpeaker) {
        SharedPreferences.Editor editor = getSp(context).edit();
        editor.putBoolean("isSettingMsgSpeaker", isSettingMsgSpeaker);
        editor.commit();
    }

    public static boolean getSettingMsgSpeaker(Context context) {
        SharedPreferences sp = getSp(context);
        boolean isSettingMsgSpeaker = sp.getBoolean("isSettingMsgSpeaker", true);
        return isSettingMsgSpeaker;
    }

    /**
     * 获取群组是否同步
     *
     * @param context
     * @param synced
     */
    public static void setGroupSynced(Context context, boolean synced) {
        SharedPreferences.Editor editor = getSp(context).edit();
        editor.putBoolean("synced", synced);
        editor.commit();
    }

    public static boolean getGroupSynced(Context context) {
        SharedPreferences sp = getSp(context);
        boolean synced = sp.getBoolean("synced", false);
        return synced;
    }

    /**
     * 获取是否允许聊天室群主离开
     *
     * @param context
     * @param allowChatroomOwnerLeave
     */
    public static void setallowChatroomOwnerLeave(Context context, boolean allowChatroomOwnerLeave) {
        SharedPreferences.Editor editor = getSp(context).edit();
        editor.putBoolean("allowChatroomOwnerLeave", allowChatroomOwnerLeave);
        editor.commit();
    }

    public static boolean getallowChatroomOwnerLeave(Context context) {
        SharedPreferences sp = getSp(context);
        boolean allowChatroomOwnerLeave = sp.getBoolean("allowChatroomOwnerLeave", false);
        return allowChatroomOwnerLeave;
    }

    /**
     * 获取退出群主是否删除所有数据
     *
     * @param context
     * @param deleteMessagesAsExitGrou
     */
    public static void setDeleteMessagesAsExitGrou(Context context, boolean deleteMessagesAsExitGrou) {
        SharedPreferences.Editor editor = getSp(context).edit();
        editor.putBoolean("deleteMessagesAsExitGrou", deleteMessagesAsExitGrou);
        editor.commit();
    }

    public static boolean getDeleteMessagesAsExitGrou(Context context) {
        SharedPreferences sp = getSp(context);
        boolean deleteMessagesAsExitGrou = sp.getBoolean("deleteMessagesAsExitGrou", true);
        return deleteMessagesAsExitGrou;
    }

    /**
     * 获取是否自动接收入群邀请
     *
     * @param context
     * @param autoAcceptGroupInvitation
     */
    public static void setAutoAcceptGroupInvitation(Context context, boolean autoAcceptGroupInvitation) {
        SharedPreferences.Editor editor = getSp(context).edit();
        editor.putBoolean("autoAcceptGroupInvitation", autoAcceptGroupInvitation);
        editor.commit();
    }

    public static boolean getAutoAcceptGroupInvitation(Context context) {
        SharedPreferences sp = getSp(context);
        boolean autoAcceptGroupInvitation = sp.getBoolean("autoAcceptGroupInvitation", true);
        return autoAcceptGroupInvitation;
    }

    /**
     * 获取视频是否自适应编码
     *
     * @param context
     * @param adaptiveVideoEncod
     */
    public static void setAdaptiveVideoEncod(Context context, boolean adaptiveVideoEncod) {
        SharedPreferences.Editor editor = getSp(context).edit();
        editor.putBoolean("adaptiveVideoEncod", adaptiveVideoEncod);
        editor.commit();
    }

    public static boolean getAdaptiveVideoEncod(Context context) {
        SharedPreferences sp = getSp(context);
        boolean adaptiveVideoEncod = sp.getBoolean("adaptiveVideoEncod", true);
        return adaptiveVideoEncod;
    }


    public static void setLoginUserName(Context context, String loginUserName) {
        SharedPreferences.Editor editor = getSp(context).edit();
        editor.putString("loginUserName", loginUserName);
        editor.commit();
    }

    /**
     * 获取登录的用户名
     *
     * @param context
     */
    public static String getLoginUserName(Context context) {
        SharedPreferences sp = getSp(context);
        String loginUserName = sp.getString("loginUserName", "");
        return loginUserName;
    }

    public static void setLoginAvatar(Context context, String loginAvatar) {
        SharedPreferences.Editor editor = getSp(context).edit();
        editor.putString("loginAvatar", loginAvatar);
        editor.commit();
    }

    /**
     * 获取登录的avatar
     *
     * @param context
     */
    public static String getLoginAvatar(Context context) {
        SharedPreferences sp = getSp(context);
        String loginAvatar = sp.getString("loginAvatar", "");
        return loginAvatar;
    }

    public static void setLoginHuanxin_id(Context context, String loginHuanxin_id) {
        SharedPreferences.Editor editor = getSp(context).edit();
        editor.putString("loginHuanxin_id", loginHuanxin_id);
        editor.commit();
    }

    /**
     * 获取登录的环信id
     *
     * @param context
     */
    public static String getLoginHuanxin_id(Context context) {
        SharedPreferences sp = getSp(context);
        String loginHuanxin_id = sp.getString("loginHuanxin_id", "");
        return loginHuanxin_id;
    }

    public static void setLoginphone(Context context, String loginPhone) {
        SharedPreferences.Editor editor = getSp(context).edit();
        editor.putString("loginPhone", loginPhone);
        editor.commit();
    }

    /**
     * 获取登录的手机号码
     *
     * @param context
     */
    public static String getLoginphone(Context context) {
        SharedPreferences sp = getSp(context);
        String loginPhone = sp.getString("loginPhone", "");
        return loginPhone;
    }


}
